package datastructure.unionfind;

import java.util.Random;

public class UFTMain {
    public static void main(String[] args) {
        System.out.println("并查集 begins");
        System.out.println(testUf(new UnionFind1(100000), 1000));
        System.out.println(testUf(new UnionFind2(100000), 1000));

    }

    private static double testUf(UF uf, int m) {
        int size = uf.getSize();
        Random random = new Random();
        long startTime = System.nanoTime();

        for (int i = 0; i < m; i++) {
            int a = random.nextInt(size);
            int b = random.nextInt(size);
            uf.isConnect(a, b);
        }

        long endTime = System.nanoTime();
        return (endTime - startTime) / 1000000000.0;
    }
}
